<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p></p>
    <button>点我看看</button>
    <script>
        function sum(a,b){
            console.log(this);
            return a + b
        }
        let newFn = sum.bind(document.querySelector('p'),100,200)
        let obj = {name:'jack',money:1}
        let res = newFn.call(obj,200,400)
        console.log(res);

        //使用场景：改变定时器中的this，还成p元素
        let p = document.querySelector('p;;;;;;;;;;;;;')
        setInterval(function(){
            console.log(this);
        }.bind(p),1000)

        // 使用场景：事件委托时，通过bind改变事件处理函数的this
        document.querySelector('button').addEventListener('click',function(){
            this.money++
        }.bind(obj))

    </script>
</body>
</html>